package base 
{
	import appkit.responders.NResponder;
	import base.constants.Events;
	import flash.utils.getQualifiedSuperclassName;
	import flash.events.MouseEvent;
	import tweens.Tween;
	
	/*
	 * For now, disabled dynam shapes because of collision problems
	 * Using basic shapes for collision and interaction
	 * 
	 * OR
	 * 
	 * shrink dynamic shape?
	 * */
	
	public class GObject extends GPoint 
	{
		protected var shape:GShape;
		protected var dynam:GShape;
		protected var lock:Boolean = false;
		

		public function unlock():void
		{
			lock = false;
		}
		
		public function hitUpdate(hit:Boolean, shapes:Vector.<GObject>=null, actives:Vector.<GObject>=null):void
		{
			 return;
		}
		
		public function on_click(e:MouseEvent):void
		{
			if (!lock)
			{
				lock = true;
				flip();
				NResponder.dispatch(Events.Selected, [this]);
			}
		}
		
		public function flip(on:uint = 1):void
		{
			//var tween:Tween = new Tween(dynam, { alpha: { start:dynam.alpha, end:dynam.alpha ^ 1, steps:10 }}, Tween.circleInOut);
			var tween:Tween = new Tween(dynam, { alpha: { start:dynam.alpha, end:on, steps:10 }}, Tween.circleInOut);
			tween.start();
		}
		
		public function disable():void
		{
			NResponder.remove(MouseEvent.CLICK, on_click, this);
		}
		
		public function enable():void
		{
			NResponder.addNative(this, MouseEvent.CLICK, on_click);
		}

		public function everyShape(item:GObject, index:int, vector:Vector.<GObject>):Boolean
		{
			if (item != this)
				return !this.hitTestObject(item);
			return true;
		}
		
		public function type():String
		{
			return getQualifiedSuperclassName(this);
		}
		
		public function GObject(s:GShape = null)
		{
			shape = s;
			dynam = shape.circumscribe();
			addChildAt(shape, 0);
			addChildAt(dynam, 1);
		}
	}

}